package com.atguigu.dao.Impl;

import com.atguigu.dao.BaseDao;
import com.atguigu.dao.UserDao;
import com.atguigu.pojo.User;

/**
 * @ClassName UserDaoImpl
 * @Description TODO
 * @Author 周轩霆
 * @Date 2022/4/9 15:35
 **/

public class UserDaoImpl extends BaseDao implements UserDao {
  /**
   * @Author 周轩霆
   * @Description 根据用户名查询用户信息
   * @Date 15:36 2022/4/9
   * @Param [name]
   * @return 
  */
    @Override
    public User queryUserByUsername(String username) {
        //String sql = "select `id`,`username`,`password`,`email` from t_user where username= ?";
        String sql = "select * from t_user where username= ?";
        return queryForOne(User.class, sql, username);
    }
/**
 * @Author 周轩霆
 * @Description  用于用户登录
 * @Date 15:36 2022/4/9
 * @Param [username, password]
 * @return 返回null则登录失败，用户名或者密码错误
*/
    @Override
    public User queryUserByUsernameAndPassword(String username, String password) {
        String sql = "select `id`,`username`,`password`,`email` from t_user where username= ? and password= ? ";
        return queryForOne(User.class, sql, username,password);
    }

    /**
     * @Author 周轩霆
     * @Description 用于保存数据
     * @Date 15:52 2022/4/9
     * @Param [user]
     * @return int
    */
    @Override
    public int saveUser(User user) {
         String sql = "insert into t_user(`username`,`password`,`email`) values(?,?,?) ";
         return update(sql,user.getUsername(),user.getPassword(),user.getEmail());
         //相当与insert

    }
}
